import { ref } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'
export function lazyLoad (fn) {
  const goods = ref([])
  const target = ref(null)
  const { stop } = useIntersectionObserver(
    target,
    ([{ isIntersecting }], option) => {
      if (isIntersecting) {
        stop()
        fn().then(res => {
          goods.value = res.result
        })
      }
    }
  )

  return { goods, target }
}
